package com.david.viewtest

import android.graphics.Matrix
import android.graphics.drawable.BitmapDrawable
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.ImageView.ScaleType
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DecodeFormat


class ImageTestActivity: AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_image_test)
        Glide.with(this)
            .load("https://zeekrlife-oss.zeekrlife.com/IMAGE/1/manage/2102/zeekrlife-mp-osp/20220701/903d048d61454e79ba78dc9643a90a5b.jpg")
            .format(DecodeFormat.PREFER_RGB_565)
            .into(findViewById(R.id.imageview))
        findViewById<ImageView>(R.id.imageview).let {img ->

            val drawable = img.drawable as BitmapDrawable
            val bitmap = drawable.bitmap
            val width = bitmap.width
            val height = bitmap.height

            val matrix = Matrix()
            val scaleWidth = img.width.toFloat() / width.toFloat()
            val scaleHeight = img.height.toFloat() / height.toFloat()
            matrix.postScale(scaleWidth, scaleHeight, 0f, 0f)
            img.imageMatrix = matrix
            img.scaleType = ScaleType.MATRIX
        }
    }
}